package net.zabuchy.meeting.bo;
 
import java.util.Date;
import java.util.List;
 
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
 
import net.zabuchy.authenticationHelper.AuthenticationHelper;
import net.zabuchy.helper.SessionHelper;
import net.zabuchy.meeting.dao.MeetingDao;
import net.zabuchy.meeting.entity.Meeting;
import net.zabuchy.user.dao.UserDao;
import net.zabuchy.user.entity.User;
 
@Transactional
public class MeetingBoImpl implements MeetingBo {
 
    private static final Logger LOGGER = Logger.getLogger(MeetingBoImpl.class.getName());
 
    @Autowired
    private MeetingDao meetingDao;
 
    @Autowired
    private AuthenticationHelper authenticationHelper;
    
    @Autowired
    private SessionHelper sessionBean;
    
    
    public void add(Meeting meeting) {
        if (meeting == null) {
            return;
        }
        LOGGER.debug("meetingBoImpl sessionUser : " + sessionBean.getExecutor().getUsername());
        
        meeting.setCustomerId(sessionBean.getCustomerId());
        meeting.setAuthor(sessionBean.getExecutor().getUsername());
        Date creationDate = new Date();
        LOGGER.debug("meetingBoImpl data1 : " + creationDate.toString());
        meeting.setCreationDate(creationDate);
        LOGGER.debug("Adding the following meeting: " + meeting.getTitle());
        meetingDao.add(meeting);
    }
 
    public void delete(Meeting meeting) {
        if (meeting == null) {
            return;
        }
        LOGGER.debug("Deleteting the following meeting: " + meeting.getTitle());
        meetingDao.delete(meeting);
    }
 
    public List findAll() {
        LOGGER.debug("Getting all meetings");
        return meetingDao.findAll();
    }
 
    public Meeting findById(int id) {
        return meetingDao.findById(id);
    }
 
    
 
    public void update(Meeting meeting) {
        if (meeting == null) {
            return;
        }
        meetingDao.update(meeting);
    }

	public MeetingDao getMeetingDao() {
		return meetingDao;
	}

	public void setMeetingDao(MeetingDao meetingDao) {
		this.meetingDao = meetingDao;
	}

	public AuthenticationHelper getAuthenticationHelper() {
		return authenticationHelper;
	}

	public void setAuthenticationHelper(AuthenticationHelper authenticationHelper) {
		this.authenticationHelper = authenticationHelper;
	}

	public SessionHelper getSessionBean() {
		return sessionBean;
	}

	public void setSessionBean(SessionHelper sessionBean) {
		this.sessionBean = sessionBean;
	}
    
    
}